﻿
CREATE PROCEDURE [dbo].[proc_Employee_Wage_BMove_GetItem]
	(
		@Id int
	)
AS
--	Declare @RuZhiDate DateTime 
--	Select @RuZhiDate=RuZhiDate From Employee Where Id=@Id
--
--	Select 
--	(isnull((select Wage from Grade where id=E.BGradeId),0)) as BasicWage
--	,(isnull((select p.PostWage from Post p where p.id=E.BPostId),0)) as PostWage
--	,(isnull((datediff(dd,@RuZhiDate,getdate())/360*100),0)) as WorkWage
--	,(isnull((select JxWage from Post where id=E.BPostId),0)) as JxWage
--	,(isnull((select ManQin from Post where id=E.BPostId),0)) as ManQin
--	,(isnull((select AName from Employee_Allowance EA where id=(select Allowance from post p where p.id=E.BPostId)),'''')) as AllowanceName
--	,(isnull((select amount from Employee_Allowance EA where id=(select Allowance from post p where p.id=E.BPostId)),0)) as Allowance
--	
--	From Employee_PostMove E
--	Where E.EId=@Id
	
	Declare @RuZhiDate DateTime,@Pid int,@Cid int,@UserName nvarchar(50)
	Select @RuZhiDate=RuZhiDate,@Pid=Pid,@Cid=Cid,@UserName=UserName From Employee Where Id=@Id

	Select 
	(isnull((select Wage from Grade where id=E.BGradeId),0)) as BasicWage
	,(isnull((select p.PostWage from Post p where p.id=E.BPostId),0)) as PostWage
	--,(isnull((datediff(dd,@RuZhiDate,getdate())/360*100),0)) as WorkWage
	,(datediff(mm,ISNULL(@RuZhiDate,GetDate()),GetDate())/12*100) as WorkWage
	,(isnull((select JxWage from Post where id=E.BPostId),0)) as JxWage
	,(isnull((select ManQin from Post where id=E.BPostId),0)) as ManQin
	,(isnull((select AName from Employee_Allowance EA where id=(select Allowance from post p where p.id=E.BPostId)),'''')) as AllowanceName
	,isnull((select sum(EA.Amount) from Employee_Allowance EA where EA.postid=E.BPostId And EA.Pid=@Pid And EA.Cid=@Cid),0) as Allowance
	,IsNull((Select Sum(FA.Amount) From Employee_FixedAllowance FA Where FA.UserName = @UserName),0) as FixedAllowance
	From Employee_PostMove E
	Where E.EId=@Id
	RETURN
